package com.yk;

import java.util.Comparator;
import java.util.TreeSet;

public class TreeSetDemo {
    public static void main(String[] args) {
        Test();
        Test2();
        Test3();
        int sum = sum(1, 2, 3, 4, 5);
        System.out.println(sum);
    }

    private static void Test() {
            TreeSet <Integer> set = new TreeSet<>();

            set.add(1);
            set.add(9);
            set.add(3);
            set.add(10);
            set.add(2);

            for (Integer integer : set) {
                System.out.println(integer);
            }


        }

    public static void Test2() {System.out.println("---------------------------------");
        TreeSet <Student> set = new TreeSet<>();
        set.add(new Student("Tom", 18));
        set.add(new Student("Jerry", 19));
        set.add(new Student("Alice", 17));

        for (Student student : set) {
            System.out.println(student.getName()+"---"+student.getAge());
        }
    }

    public static void Test3(){System.out.println("---------------------------------");

        Comparator<Student> comparator = Comparator.comparing(Student::getName);

        TreeSet<Student> set = new TreeSet<>(comparator);
        set.add(new Student("Tom", 18));
        set.add(new Student("Jerry", 19));
        set.add(new Student("Alice", 17));

        for (Student student : set) {
            System.out.println(student.getName()+"---"+student.getAge());
        }

    }

    public static int sum(int... a){System.out.println("---------------------------------");
        int total = 0;
        for (int i = 0; i < a.length; i++) {
            total += a[i];
        }
        return total;
    }

    }


